package com.ming.seatMonitoring.service.ServiceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ming.seatMonitoring.mapper.UseManageMapper;
import com.ming.seatMonitoring.pojo.DO.BookRoomInfoDO;
import com.ming.seatMonitoring.pojo.DO.UseManageDO;
import com.ming.seatMonitoring.service.UseManageService;
import com.ming.seatMonitoring.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author 小明
 * @date 2021/10/23
 * @description
 */
@Service
public class UseManageServiceImpl extends ServiceImpl<UseManageMapper, BookRoomInfoDO> implements UseManageService {
    @Autowired
    UseManageMapper useManageMapper;

    @Override
    public int[] getWeek(int roomId) {

        int[] arr = new int[7];

        for (int i = 0; i < 7; i++) {
            //获取历史日期
            final QueryWrapper<BookRoomInfoDO> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("roomId",roomId);
            final String week = DateUtil.getWeek(7-i);
            queryWrapper.eq("bookDate",week);
            arr[i]=useManageMapper.selectCount(queryWrapper);
        }
        return arr;
    }

    @Override
    public int getCountByRoomId(int roomId) {
        final QueryWrapper<BookRoomInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("roomId",roomId);
        return useManageMapper.selectCount(queryWrapper);
    }

    @Override
    public Page<BookRoomInfoDO> getCountByUserId(Page<BookRoomInfoDO> page, String userId) {

        return useManageMapper.getCountByUserId(page,userId);
    }

    @Override
    public int getTotal(String userId) {
        final QueryWrapper<BookRoomInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        return useManageMapper.selectCount(queryWrapper);
    }

    @Override
    public Page<BookRoomInfoDO> getListByRoomId(Page<BookRoomInfoDO> page, int roomId) {
        return useManageMapper.getListByRoomId(page,roomId);
    }

}
